"use strict";
cc._RF.push(module, '3d5e4nZjG5BP55eqz4dWeWE', 'LevelManager');
// scripts/LevelManager.js

"use strict";

var e = require;
var t = module;
var n = s(e("GiftBoxMgr")),
    o = s(e("YaoshuiMgr")),
    i = s(e("RecorderPanel")),
    a = s(e("UIManager")),
    r = s(e("SoundMgr"));

function s(e) {
  return e && e.__esModule ? e : {
    "default": e
  };
}

window.LevelManager = {
  Instance: null
};
var c = e("LevelSceneManager"),
    l = cc.Enum({
  Lobby: 0,
  Jail: 1,
  Story: 2
}),
    d = cc.Enum({
  Attack: 0,
  Defense: 1
}),
    h = cc.Enum({
  OldKing: 0,
  BlackKing: 1,
  BlackKiller: 2,
  YellowKiller: 3,
  RedDrinkSteward: 4,
  GreenDrinkSteward: 5,
  Clown: 6,
  Woman: 7,
  Army: 8,
  Master: 9,
  Girl: 10,
  Dancer: 11
});
cc.Enum({
  TooYoung: 0,
  Young: 1,
  Old: 2,
  TooOld: 3
});
t.exports = {
  GameSceneBlockType: l,
  GameOperationMode: d,
  AvatarControllerType: h
};
cc.Class({
  "extends": cc.Component,
  properties: {
    SceneMainAudioSource: cc.AudioSource,
    SceneMainCameraNode: cc.Node,
    SceneCanvasContentNode: cc.Node,
    SceneBlockContentNode: cc.Node,
    SceneContentNode: cc.Node,
    KingBackHeadSpriteNode: cc.Node,
    AllowAvatarControllerMove: {
      type: Boolean,
      "default": !0
    },
    GameAllowOperation: {
      type: Boolean,
      "default": !0
    },
    PointerIsDown: {
      type: Boolean,
      "default": !1
    },
    GameCurrentOperationScene: {
      type: l,
      "default": l.Lobby
    },
    _GameCurrentOperationMode: {
      type: d,
      "default": d.Attack
    },
    GameCurrentOperationMode: {
      get: function get() {
        return this._GameCurrentOperationMode;
      },
      set: function set(e) {
        this._GameCurrentOperationMode = e;
        this.onGameCurrentOperationModeChange();
      }
    },
    RestartGameContent: cc.Node,
    BackgroundRaycast: cc.Node,
    AttackProgressBar: cc.ProgressBar,
    HealthProgressBar: cc.ProgressBar,
    AttackProgressBarMoveSpeed: 0,
    HealthProgressBarMoveSpeed: 0,
    LevelProgressNode: cc.Node,
    levelCount: 1,
    levelCountLabels: {
      type: [cc.Label],
      "default": []
    },
    AvatarControllerMoveSpeed: 0,
    AvatarControllerFastMoveSpeed: 0,
    KillerAttackHandMoveSpeed: 0,
    AllowKingLeftLookTime: 2,
    AvatarControllerDistanceMinLimit: 500,
    GameCreateNPCKillerIndex: 0
  },
  onLoad: function onLoad() {
    cc.director.getPhysicsManager().enabled = !0;
    LevelManager.Instance = this;
  },
  addLevel: function addLevel(e) {
    var t = this;
    this.levelCount += e;

    if (0 == e) {
      this.levelCountLabels[0].string = (this.levelCount - 1).toString();
      this.levelCountLabels[1].string = this.levelCount.toString();
      this.levelCountLabels[2].string = (this.levelCount + 1).toString();
    } else this.scheduleOnce(function () {
      t.levelCountLabels[0].string = (t.levelCount - 1).toString();
      t.levelCountLabels[1].string = t.levelCount.toString();
      t.levelCountLabels[2].string = (t.levelCount + 1).toString();
    }, 1.5);
  },
  update: function update(e) {
    if (this.GameAllowOperation) switch (this.GameCurrentOperationMode) {
      case d.Attack:
        if (this.PointerIsDown) {
          if (KillerController.Instance.node.position.sub(NPCKingController.Instance.node.position).mag() >= this.AvatarControllerDistanceMinLimit) return;

          if (this.AttackProgressBar.progress < 1) {
            if (NPCKingController.Instance.CurrentIsDiscover) return;
            this.AttackProgressBar.progress += this.AttackProgressBarMoveSpeed * e;
          } else {
            this.AttackProgressBar.progress = 1;
            this.GameAllowOperation = !1;
            KillerController.Instance.ControllerAnimation.playAnimation("attacking", 1);
          }
        }

        break;

      case d.Defense:
        if (!this.AllowAvatarControllerMove || i["default"].GamePause) return;
        if (this.HealthProgressBar.progress < 0) return;
        this.HealthProgressBar.progress -= this.HealthProgressBarMoveSpeed * e;

        if (this.HealthProgressBar.progress < 0) {
          this.AllowAvatarControllerMove = !1;
          this.GameAllowOperation = !1;
          KingController.Instance.ControllerAnimation.playAnimation("oldDeath", 1);
        }

    }
  },
  onRaycastTouchDown: function onRaycastTouchDown() {
    if (this.GameAllowOperation) {
      console.log("onRaycastTouchDown");
      a["default"].Inst.autoClick();

      switch (this.GameCurrentOperationMode) {
        case d.Attack:
          if (KillerController.Instance.node.position.sub(NPCKingController.Instance.node.position).mag() >= this.AvatarControllerDistanceMinLimit) return;
          this.PointerIsDown = !0;
          r["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[1]);
          KillerController.Instance.ControllerAnimation.playAnimation("attack", 1);
          break;

        case d.Defense:
          this.PointerIsDown = !0;
          KingController.Instance.LeftLookDiscover();
      }
    }
  },
  onRaycastTouchUp: function onRaycastTouchUp() {
    if (this.PointerIsDown) {
      this.node.emit("click", this);
      this.PointerIsDown = !1;

      switch (this.GameCurrentOperationMode) {
        case d.Attack:
          if (this.GameAllowOperation && this.AttackProgressBar.progress < 1) {
            this.AttackProgressBar.progress = 0;
            KillerController.Instance.ControllerAnimation.playAnimation("walk", 0);
          }

          break;

        case d.Defense:
          KingController.Instance.LeftLookDiscoverOver();
      }
    }
  },
  onKingEnterKingStoryLobbyDoor: function onKingEnterKingStoryLobbyDoor() {
    if (this.HealthProgressBar.node.active && this.HealthProgressBar.progress <= .2) {
      this.AllowAvatarControllerMove = !1;
      this.GameAllowOperation = !1;
      KingController.Instance.ControllerAnimation.pause();
      this.scheduleOnce(function () {
        KingController.Instance.ControllerAnimation.play("");
      }, 1.5);
    } else {
      ColourBackground.Instance.Show(cc.color(255, 255, 255));
      this.scheduleOnce(function () {
        this.GameAllowOperation = !1;
        LevelSceneManager.Instance.StartStoryScene(c.GameStorySceneType.King);
        KingController.Instance.node.active = !1;
        NPCKillerController.Instance.node.active = !1;
      }, 1);
    }
  },
  onGameOver: function onGameOver() {
    this.RestartGameContent.active = !0;
    KingController.Instance && KingController.Instance.node.destroy();
    NPCKillerController.Instance && NPCKillerController.Instance.node.destroy();
    this.AttackProgressBar.node.active = !1;
    n["default"].Instance.HideBox();
    this.HealthProgressBar.node.active = !1;
    this.LevelProgressNode.active = !1;
    this.enabled = !1;
  },
  CreateArmyController: function CreateArmyController(e, t) {
    var n = cc.instantiate(AssetManager.Instance.ControllerPrefabs[8]);
    n.parent = this.SceneContentNode;
    n.position = cc.v2(e.x - 800, e.y);
    var o = n.getComponent("ArmyGroupController");
    o.TargetAvatarNode = e;
    o.TargetAvatarControllerType = t;
  },
  CreateRandomNPCKiller: function CreateRandomNPCKiller() {
    if (null == NPCKillerController.Instance) {
      var e = cc.instantiate(AssetManager.Instance.ControllerPrefabs[3]);
      5 == this.GameCreateNPCKillerIndex && (this.GameCreateNPCKillerIndex = 6);

      switch (this.GameCreateNPCKillerIndex) {
        case 0:
          e = cc.instantiate(AssetManager.Instance.ControllerPrefabs[3]);
          break;

        case 1:
          e = cc.instantiate(AssetManager.Instance.ControllerPrefabs[6]);
          break;

        case 2:
          e = cc.instantiate(AssetManager.Instance.ControllerPrefabs[5]);
          break;

        case 3:
          e = this.HealthProgressBar.node.active ? cc.instantiate(AssetManager.Instance.ControllerPrefabs[4]) : cc.instantiate(AssetManager.Instance.ControllerPrefabs[3]);
          break;

        case 4:
          e = cc.instantiate(AssetManager.Instance.ControllerPrefabs[7]);
          break;

        case 5:
          e = cc.instantiate(AssetManager.Instance.ControllerPrefabs[9]);
          break;

        case 6:
          e = cc.instantiate(AssetManager.Instance.ControllerPrefabs[10]);
          break;

        case 7:
          e = cc.instantiate(AssetManager.Instance.ControllerPrefabs[11]);
      }

      this.GameCreateNPCKillerIndex++;
      this.GameCreateNPCKillerIndex >= 8 && (this.GameCreateNPCKillerIndex = 0);
      e.parent = this.SceneContentNode;
      var t = KingController.Instance.node.position;
      t.x -= 1300;
      e.position = t;
    }
  },
  onGameCurrentOperationModeChange: function onGameCurrentOperationModeChange() {
    this.AttackProgressBar.progress = 0;
    this.HealthProgressBar.progress = 1;

    switch (this.GameCurrentOperationMode) {
      case d.Attack:
        this.AttackProgressBar.node.active = !0;
        n["default"].Instance.ShowBox();
        this.HealthProgressBar.node.active = !1;
        this.LevelProgressNode.active = !1;
        o["default"].Instance.Hide();
        break;

      case d.Defense:
        this.AttackProgressBar.node.active = !1;
        n["default"].Instance.HideBox();
        this.HealthProgressBar.node.active = !0;
        this.LevelProgressNode.active = !0;
        this.addLevel(0);
    }
  }
});

cc._RF.pop();